//
// DirectoryIterator.cpp
//
// $Id: //poco/1.4/Foundation/src/DirectoryIterator.cpp#1 $
//
// Library: Foundation
// Package: Filesystem
// Module:  DirectoryIterator
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/DirectoryIterator.h"
#if defined(POCO_OS_FAMILY_UNIX)
    #include "DirectoryIterator_UNIX.cpp"
#endif
namespace Poco {


DirectoryIterator::DirectoryIterator(): m_pImpl(0)
{
}

	
DirectoryIterator::DirectoryIterator(const std::string& path): m_path(path), m_pImpl(new DirectoryIteratorImpl(path))
{
	m_path.makeDirectory();
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
}


DirectoryIterator::DirectoryIterator(const DirectoryIterator& iterator): m_path(iterator.m_path), m_pImpl(iterator.m_pImpl)
{
	if (m_pImpl) 
	{
		m_pImpl->duplicate();
		m_file = m_path;
	}
}

	
DirectoryIterator::DirectoryIterator(const File& file): m_path(file.path()), m_pImpl(new DirectoryIteratorImpl(file.path()))
{
	m_path.makeDirectory();
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
}


DirectoryIterator::DirectoryIterator(const Path& path): m_path(path), m_pImpl(new DirectoryIteratorImpl(path.toString()))
{
	m_path.makeDirectory();
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
}


DirectoryIterator::~DirectoryIterator()
{
	if (m_pImpl) m_pImpl->release();
}


DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it)
{
	if (m_pImpl) m_pImpl->release();
	m_pImpl = it.m_pImpl;
	if (m_pImpl) 
	{
		m_pImpl->duplicate();
		m_path = it.m_path;
		m_file = m_path;
	}
	return *this;
}


DirectoryIterator& DirectoryIterator::operator = (const File& file)
{
	if (m_pImpl) m_pImpl->release();
	m_pImpl = new DirectoryIteratorImpl(file.path());
	m_path.parseDirectory(file.path());
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
	return *this;
}


DirectoryIterator& DirectoryIterator::operator = (const Path& path)
{
	if (m_pImpl) m_pImpl->release();
	m_pImpl = new DirectoryIteratorImpl(path.toString());
	m_path = path;
	m_path.makeDirectory();
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
	return *this;
}


DirectoryIterator& DirectoryIterator::operator = (const std::string& path)
{
	if (m_pImpl) m_pImpl->release();
	m_pImpl = new DirectoryIteratorImpl(path);
	m_path.parseDirectory(path);
	m_path.setFileName(m_pImpl->get());
	m_file = m_path;
	return *this;
}


DirectoryIterator& DirectoryIterator::operator ++ ()
{
	if (m_pImpl)
	{
		m_path.setFileName(m_pImpl->next());
		m_file = m_path;
	}
	return *this;
}


DirectoryIterator DirectoryIterator::operator ++ (int dummy)
{
	if (m_pImpl)
	{
		m_path.setFileName(m_pImpl->next());
		m_file = m_path;
	}
	return *this;
}


} // namespace Poco
